function getDiagramSvg(){const t=document.querySelector(".msd-container svg");return t||(console.error("No SVG found in .msd-container"),null)}function getTitle(){const t=document.querySelector(".page-title");return t?t.innerText:""}function getExportDimensions(t){const e=t.querySelector(".main-group"),n=t.querySelector(".participants");let o;if(e&&n){const r=e.getBBox(),i=n.getBBox(),a=n.getAttribute("transform");let s=i.y;if(a){const t=/translate\(([^,]+),\s*([^)]+)\)/.exec(a);t&&(s+=parseFloat(t[2]))}Math.min(r.x,i.x),Math.min(r.y,s);o=t.getBBox()}else o=e?e.getBBox():t.getBBox();return{width:o.width+200,height:o.height+120,viewBoxX:o.x-100,viewBoxY:o.y-60}}function generateSvgData(){window.svg&&window.zoom&&window.d3&&window.svg.call(window.zoom.transform,window.d3.zoomIdentity);const t=document.querySelector(".main-content-container");t&&(window.isRestoringScroll=!0,t.scrollTop=0);const e=getDiagramSvg();if(e){const t=e.querySelector("g.participants");if(t){const e=0;t.setAttribute("transform",`translate(0, ${e})`),t.style.opacity="1"}}const n=getDiagramSvg();if(!n)return null;const o=n.cloneNode(!0),r=getExportDimensions(n);o.setAttribute("width",r.width),o.setAttribute("height",r.height),o.setAttribute("viewBox",`${r.viewBoxX} ${r.viewBoxY} ${r.width} ${r.height}`);const i=window.getComputedStyle(document.documentElement).backgroundColor,a=window.getComputedStyle(document.body).backgroundColor;let s=i;s&&"rgba(0, 0, 0, 0)"!==s&&"transparent"!==s||(s=a),s&&"rgba(0, 0, 0, 0)"!==s&&"transparent"!==s||(s="#ffffff");const g=document.createElementNS("http://www.w3.org/2000/svg","rect");g.setAttribute("x",r.viewBoxX),g.setAttribute("y",r.viewBoxY),g.setAttribute("width",r.width),g.setAttribute("height",r.height),g.setAttribute("fill",s),o.prepend(g);const c=document.createElement("style");c.textContent="\n        text { font-family: sans-serif; }\n        .actor { fill: #fff; stroke: #000; stroke-width: 2px; }\n        .messageLine0 { stroke-width: 1.5; fill: none; }\n        /* Add other critical styles here or fetch from stylesheets */\n    ",o.prepend(c);const d=window.getComputedStyle(document.documentElement);window.getComputedStyle(document.body);(d.filter&&d.filter.includes("invert")||document.documentElement.style.filter&&document.documentElement.style.filter.includes("invert"))&&(o.style.filter="invert(1) hue-rotate(180deg)",o.style.setProperty("--participant-bg-color","#FFFFFF"));let l=(new XMLSerializer).serializeToString(o);return l.startsWith("<?xml")||(l='<?xml version="1.0" standalone="no"?>\r\n'+l),t&&(window.isRestoringScroll=!1),l}function generatePngData(){return new Promise((t,e)=>{const n=generateSvgData();if(!n)return void e("Could not generate SVG data");const o=getExportDimensions(getDiagramSvg()),r=2*o.width,i=2*o.height,a=document.createElement("canvas");a.width=r,a.height=i;const s=a.getContext("2d"),g=window.getComputedStyle(document.documentElement).backgroundColor,c=window.getComputedStyle(document.body).backgroundColor;let d=g;d&&"rgba(0, 0, 0, 0)"!==d&&"transparent"!==d||(d=c),d&&"rgba(0, 0, 0, 0)"!==d&&"transparent"!==d||(d="#ffffff"),s.fillStyle=d,s.fillRect(0,0,r,i);const l=new Image,u=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),m=URL.createObjectURL(u);l.onload=()=>{s.drawImage(l,0,0,r,i),URL.revokeObjectURL(m),t(a.toDataURL("image/png"))},l.onerror=t=>{URL.revokeObjectURL(m),e(t)},l.src=m})}async function generatePdfData(){try{const t=await generatePngData(),e=getExportDimensions(getDiagramSvg()),n=.264583*e.width,o=.264583*e.height,{jsPDF:r}=window.jspdf,i=new r({orientation:n>o?"landscape":"portrait",unit:"mm",format:[n,o]});return i.addImage(t,"PNG",0,0,n,o),i.output("datauristring")}catch(t){return console.error("Error generating PDF:",t),null}}window.generateSvgData=generateSvgData,window.generatePngData=generatePngData,window.generatePdfData=generatePdfData;